<template>

  <div>

    <el-card class="box-card"  >
      <div>
        <div class="map">
          <div style="float:left;display: inline-block" >
            <div id="myChart" style="width: 300px; height: 230px;" ></div>
            <div id="myChart1" style="width: 300px; height: 230px;"></div>
            <div id="myChart2" style="width: 300px; height: 230px; " ></div>
          </div>


          <div class="no" style="display: inline-block;width: 350px">
            <div>
              <div class="no-hd">
                <ul>
                  <li>{{ total }}￥</li>
                  <li style="list-style:none"> {{ profit }}￥</li>
                </ul>
              </div>
              <div class="no-bd">
                <ul>
                  <li>总营业额</li>
                  <li>本月总利润</li>
                </ul>
              </div>
            </div>

          </div>


<!--        <div style="float:left;display: inline-block;position: relative;height: 80rem;">-->
<!--          <el-collapse>-->
<!--            <span style="float: right">🔥🔥系统公告🔥🔥</span>-->
<!--            <br><br>-->
<!--            <el-collapse-item>-->
<!--              <div>1234567</div>-->
<!--              <div>1234567</div>-->
<!--              <div>1234567</div>-->
<!--              <div>1234567</div>-->
<!--            </el-collapse-item>-->
<!--          </el-collapse>-->
<!--        </div>-->






          <div style="float:right;display: inline-block">
            <div id="myChart3" style="width: 300px; height: 230px;" ></div>
            <div id="myChart4" style="width: 300px; height: 230px;"></div>
            <div id="myChart5" style="width: 300px; height: 230px; " ></div>
          </div>

          <div class="map1"></div>
          <div class="map2"></div>
          <div class="map3"></div>


        </div>
      </div>




    </el-card>

  </div>
</template>

<link rel="stylesheet" href="src/assets/index.css" />

<script>

import * as echarts from 'echarts';
import request from "@/utils/request";
export default {

  data() {
    return {
      date:[],
      total:0,
      profit:0,
    };
  },
  mounted() {
    this.midEcharts();
    this.midEcharts1();
    this.findEcharts();
    this.findEcharts1();
    this.findEcharts2();
    this.findEcharts3();
    this.findEcharts4();
    this.findEcharts5();
    this.findEcharts5();

  },
  methods: {

    midEcharts(){
      request.get("/inventory/mid").then( res => {
         this.total  = res.data.data
      })
    },

    midEcharts1(){
      request.get("/inventory/mid1").then( res => {
        this.profit  = res.data.data
      })
    },

    findEcharts(){
      request.get("/inventory/Search").then( res => {
        this.drawLine(res.data.data)
      })
    },


    drawLine(data){
      console.log("dsdsd"+data);
      var chartDom = document.getElementById('myChart');
      var myChart = echarts.init(chartDom);
      var option;
      let x = [];
      let y = [];
      for (let i = 0; i < data.length; i++) {
        //x[i]获取json的姓名，y[i]获取json的值
        x[i] = data[i].name;
        y[i] = data[i].value;
      }

      option = {
        tooltip: {},
        label: {
          show: true,
          position:'top',
        },
        legend: {},
        xAxis: {
          data: x
        },
        dataZoom: {
          type: 'inside',  //放大缩小x轴数值
        },
        yAxis: {},
        series: [
          {
            colorBy:'data',
            name: '本月销量',
            type: 'bar',
            data: y
          }
        ]

      };

      option && myChart.setOption(option);

    },

    findEcharts1(){
      request.get("/inventory/Search1").then( res => {
        this.drawLine1(res.data.data)
      })
    },


    drawLine1(data){
      console.log("折线图"+data);

      var chartDom = document.getElementById('myChart1');
      var myChart1 = echarts.init(chartDom);
      var option;
      let x = [];
      let y = [];
      let z = [];
      for (let i = 0; i < data.length; i++) {
        //x[i]获取json的姓名，y[i]获取json的值
        x[i] = data[i].name;
        y[i] = data[i].value;
        z[i] = data[i].key;
      }


      option = {
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['上月销量', '本月销量']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        xAxis: {
          type: 'category',
          boundaryGap: true,
          data: x
        },
        dataZoom: {
          type: 'inside',  //放大缩小x轴数值
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            name: '上月销量',
            type: 'line',
            stack: 'Total',
            data: y,
            smooth: true
          },
          {
            name: '本月销量',
            type: 'line',
            stack: 'Total',
            data: z,
            smooth: true
          },

        ]
      };

      option && myChart1.setOption(option);
    },

    findEcharts2(){
      request.get("/inventory/Search2").then( res => {
        this.drawLine2(res.data.data)
      })
    },
    drawLine2(data){
      let chartDom2 = document.getElementById('myChart2');
      let myChart2 = echarts.init(chartDom2);
      let option;

        option = {
          title: {

            subtext: '库存商品占比',
            left: 'center'
          },
          tooltip: {
            trigger: 'item'
          },

          series: [
            {
              name: '库存商品',
              type: 'pie',
              radius: '50%',
              data: data,
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
        };

        option && myChart2.setOption(option);

    },
    findEcharts3(){
      request.get("/inventory/Search3").then( res => {
        this.drawLine3(res.data.data)
      })
    },
    drawLine3(data){

      var chartDom = document.getElementById('myChart3');
      var myChart3 = echarts.init(chartDom);
      var option;
      let x = [];
      let y = [];
      for (let i = 0; i < data.length; i++) {
        //x[i]获取json的姓名，y[i]获取json的值
        x[i] = data[i].name;
        y[i] = data[i].value;
      }

      option = {
        tooltip: {},
        label: {
          show: true,
          position:'top',
        },
        legend: {},
        xAxis: {
          data: x
        },
        dataZoom: {
          type: 'inside',  //放大缩小x轴数值
        },
        yAxis: {},
        series: [
          {
            colorBy:'data',
            name: '本月各类目商品营业额',
            type: 'bar',
            data: y
          }
        ]
      };

      option && myChart3.setOption(option);

    },
    findEcharts4(){
      request.get("/inventory/Search4").then( res => {
        this.drawLine4(res.data.data)
      })
    },
    drawLine4(data){

      var chartDom = document.getElementById('myChart4');
      var myChart4 = echarts.init(chartDom);
      var option;

      let x = [];
      let y = [];

      for (let i = 0; i < data.length; i++) {
        //x[i]获取json的姓名，y[i]获取json的值
        x[i] = data[i].name;
        y[i] = data[i].value;

      }

      option = {
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['本月各类商品带来的利润']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: x
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            name: '本月各类商品带来的利润',
            type: 'line',
            stack: 'Total',
            data: y,
            smooth: true
          },


        ]
      };

      option && myChart4.setOption(option);
    },

    findEcharts5(){
      request.get("/inventory/Search5").then( res => {
        this.drawLine5(res.data.data)
      })
    },
    drawLine5(data){
      let chartDom2 = document.getElementById('myChart5');
      let myChart5 = echarts.init(chartDom2);
      let option;
      option = {
        title: {

          subtext: '本月单类商品利润占比',
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },

        series: [
          {
            name: '单类商品利润占比',
            type: 'pie',
            radius: '50%',
            data: data,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      };

      option && myChart5.setOption(option);

    },

  }
}
</script>


<style>
.no {
  background-color: #fc3e1c;
  padding: 0.1875rem;
}
.no .no-hd {
  position: relative;
  border: 1px solid rgba(25, 186, 139, 0.17);
}
.no .no-hd::before {
  content: "";
  position: absolute;
  width: 30px;
  height: 10px;
  border-top: 2px solid #02a6b5;
  border-left: 2px solid #02a6b5;
  top: 0;
  left: 0;
}
.no .no-hd::after {
  content: "";
  position: absolute;
  width: 30px;
  height: 10px;
  border-bottom: 2px solid #02a6b5;
  border-right: 2px solid #02a6b5;
  right: 0;
  bottom: 0;
}
.no .no-hd ul {
  display: flex;
}
.no .no-hd ul li {
  position: relative;
  flex: 1;
  text-align: center;
  height: 1rem;
  line-height: 1rem;
  font-size: 1.85rem;
  color: #ffeb7b;
  padding: 0.05rem 0;
  font-family: electronicFont;
  font-weight: bold;
}
.no .no-hd ul li:first-child::after {
  content: "";
  position: absolute;
  height: 80%;
  width: 1.5px;
 background-color: #153cd3;
  right: 0;
  top: 25%;
}
.no .no-bd ul {
  display: flex;
}
.no .no-bd ul li {
  flex: 1;
  height: 0.5rem;
  line-height: 0.5rem;
  text-align: center;
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.7);
  padding-top: 0.125rem;
}


.map {
  position: relative;
  height: 20rem;
}
.map .chart {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 5;
  height: 10.125rem;
  width: 100%;
}
.map .map1,
.map .map2,
.map .map3 {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 18rem;
  height: 18rem;
  background: url(../assets/map.png) no-repeat;
  background-size: 100% 100%;
  opacity: 0.3;
}
.map .map2 {
  width: 22.0375rem;
  height: 22.0375rem;
  background-image: url(../assets/lbx.png);
  opacity: 0.6;
  animation: rotate 15s linear infinite;
  z-index: 2;
}
.map .map3 {
  width: 20.075rem;
  height: 20.075rem;
  background-image: url(../assets/jt.png);
  animation: rotate1 10s linear infinite;
}

@keyframes rotate {
  from {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}
@keyframes rotate1 {
  from {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  to {
    transform: translate(-50%, -50%) rotate(-360deg);
  }
}
@media screen and (max-width: 1024px) {
  html {
    font-size: 42px !important;
  }
}
@media screen and (min-width: 1920px) {
  html {
    font-size: 80px !important;
  }
}
</style>
